<!--
 * @Description: 员工实名认证审核
 * @Author: 萧盼盼的泰迪
 * @Date: 2021-06-24 16:17:13
 * @LastEditors: 萧盼盼的泰迪
 * @LastEditTime: 2021-07-01 21:14:58
-->
<template>
  <!-- 员工实名认证审核 -->
  <div class="Certification-list">
    <div class="search">
      <!-- {{ searchForm }} -->
      <el-form
        :inline="true"
        :model="searchForm"
        size="mini"
        class="demo-form-inline"
      >
        <el-form-item>
          <el-date-picker
            v-model="searchForm.applyTime"
            clearable
            value-format="timestamp"
            size="mini"
            type="datetimerange"
            :picker-options="pickerOptions"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            align="right"
          />
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="searchForm.status"
            clearable
            placeholder="请选择状态"
          >
            <el-option label="通过" value="通过" />
            <el-option label="不通过" value="不通过" />
            <el-option label="未审核" value="未审核" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="searchForm.userId"
            clearable
            placeholder="申请人编号"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="toSearch">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 表格 -->
    <div>
      <el-table
        v-loading="loading"
        size="small"
        :data="tableData"
        stripe
        style="width: 100%"
      >
        <el-table-column type="index" align="center" label="序号" />
        <el-table-column
          prop="userId"
          align="center"
          width="100px"
          label="申请人编号"
        />
        <el-table-column align="center" label="姓名">
          <template slot-scope="scope">
            <span v-if="scope.row.realname === null">--</span>
            <span v-else>{{ scope.row.realname }}</span>
          </template>
        </el-table-column>

        <el-table-column
          prop="applyTime"
          align="center"
          width="150px"
          label="申请时间"
        >
          <template slot-scope="scope">
            {{ moment(scope.row.applyTime).format("YYYY-MM-DD HH:mm:ss") }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="身份证号">
          <template slot-scope="scope">
            <span v-if="scope.row.idCard === null">--</span>
            <span v-else>{{ scope.row.idCard }}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="idcardPhotoPositive" label="身份证正面"></el-table-column> -->
        <el-table-column align="center" label="身份证正面">
          <template slot-scope="scope">
            <!-- scope是当前temlate模板的作用域对象，row属性上存放的是当前行的数据对象 -->
            <!-- {{scope.row.photo}} -->
            <!-- <img :src="scope.row.photo" alt /> -->
            <el-image
              style="width: 30px; height: 30px"
              :src="scope.row.idcardPhotoPositive"
              :preview-src-list="[scope.row.idcardPhotoPositive]"
            />
          </template>
        </el-table-column>
        <!-- <el-table-column prop="idcardPhotoNegative" label="身份证反面"></el-table-column> -->
        <el-table-column align="center" label="身份证反面">
          <template slot-scope="scope">
            <el-image
              style="width: 30px; height: 30px"
              :src="scope.row.idcardPhotoNegative"
              :preview-src-list="[scope.row.idcardPhotoNegative]"
            />
          </template>
        </el-table-column>
        <el-table-column align="center" label="银行卡号">
          <template slot-scope="scope">
            <span v-if="scope.row.bankCard === null">--</span>
            <span v-else>{{ scope.row.bankCard }}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="bankCardPhoto" label="银行卡"></el-table-column> -->
        <el-table-column align="center" label="银行卡">
          <template slot-scope="scope">
            <el-image
              style="width: 30px; height: 30px"
              :src="scope.row.bankCardPhoto"
              :preview-src-list="[scope.row.bankCardPhoto]"
            />
          </template>
        </el-table-column>
        <el-table-column align="center" label="状态">
          <template slot-scope="scope">
            <el-tag
              :type="scope.row.status === '通过' ? 'success' : 'danger'"
              >{{ scope.row.status }}</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="150px">
          <template slot-scope="scope">
            <el-button
              :disabled="scope.row.status === '通过'"
              type="text"
              size="small"
              icon="el-icon-check"
              @click="tocheckPass(scope.row.id)"
              >通过</el-button
            >
            <el-button
              :disabled="scope.row.status === '不通过'"
              type="text"
              size="small"
              icon="el-icon-close"
              class="red_info"
              @click="tocheckNoPass(scope.row.id)"
              >不通过</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagination-div">
      <el-pagination
        :current-page="params.page"
        :page-sizes="[2, 5, 10, 15, 20, 30]"
        :page-size="params.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script>
import moment from "moment";
import {
  pageQueryCertificationApply,
  revokeCertificationApply,
  submitCertificationApply,
  checkPass,
  checkNoPass,
} from "@/api/certification";
import { showFileURL, uploadFileURL } from "@/utils/config";

export default {
  data() {
    return {
      // searchForm: {
      //   user: "",
      //   region: "",
      // },
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      // value1: "",

      showFileURL,
      uploadFileURL,
      // 模糊搜索表单的数据
      searchForm: {
        name: "",
        status: "",
        applyTime: [],
      },
      // 表格展示的数据
      tableData: [],
      // 分页参数
      params: {
        page: 1,
        pageSize: 10,
      },
      // 总条数
      total: 0,
      // 加载
      loading: false,
      // 模态框的显示与隐藏
      visible: false,
      // 表单数据
      form: {},
      // 表单控件标题的宽度
      formLabelWidth: "80px",
    };
  },

  computed: {},
  watch: {
    // 深度监听分页参数
    params: {
      handler() {
        this.queryData();
      },
      deep: true,
    },
  },
  created() {
    this.queryData();
  },
  mounted() {},
  methods: {
    moment,
    async queryData() {
      this.loading = true;
      // 合并对象
      // 处理数据
      const temp = {
        ...this.params,
        ...this.searchForm,
      };
      // 遍历对象
      for (const key in temp) {
        // key是一个变量，代表的属性名
        // key 'page'   temp.key  temp[key]
        // key是属性名  temp[key]属性值
        // console.log(key, temp[key]);
        if (!temp[key]) {
          delete temp[key];
        }
      }
      if (temp.applyTime.length > 0) {
        temp.beginTime = temp.applyTime[0];
        temp.endTime = temp.applyTime[1];
        delete temp.applyTime;
      }
      const res = await pageQueryCertificationApply(temp);
      // 加载完毕
      this.loading = false;
      this.tableData = res.data.list;
      this.total = res.data.total;
    },
    // 查询按钮点击事件处理程序
    toSearch() {
      this.queryData();
    },
    // 每页显示的条数发生变化时的事件处理程序
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      // this.params.pageSize = val;
      // this.params.page = 1;
      this.params = {
        page: 1,
        pageSize: val,
      };
      // this.queryData()
    },
    // 当前页码发生变化时的事件处理程序
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.params.page = val;
      // this.queryData()
    },
    // toSearch() {
    //   this.queryData();
    // },
    // 通过
    async tocheckPass(id) {
      const res = await checkPass({ id });
      this.$notify.success({
        title: "成功",
        message: res.message,
      });
      this.queryData();
    },
    // 不通过
    async tocheckNoPass(id) {
      const res = await checkNoPass({ id });
      this.$notify.success({
        title: "成功",
        message: res.message,
      });
      this.queryData();
    },
  },
};
</script>
 <style lang="scss" scoped>
.search {
  display: flex;
  height: 40px;
}
</style>
